package com.innovation.chengzhangriji.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.innovation.chengzhangriji.R;

/**
 * 于 2015/12/7 15:37 由 李传智 创建
 * 如有问题需修改，请联系 chuanzhigo@gmail.com
 **/
public class AlertDialog extends Dialog implements View.OnClickListener {

    @Override
    public void onClick(View v) {
        if(onDialogClickListener != null) {
            if(v.getId() == R.id.btn_sure) {
                onDialogClickListener.sure();
            }
        }
    }

    public OnDialogClickListener getOnDialogClickListener() {
        return onDialogClickListener;
    }

    public void setOnDialogClickListener(OnDialogClickListener onDialogClickListener) {
        this.onDialogClickListener = onDialogClickListener;
    }

    private OnDialogClickListener onDialogClickListener;

    public static interface OnDialogClickListener {

        public void sure();
    }

    private TextView tipTextView;

    private Button btnSure;

    public AlertDialog(Context context) {
        super(context);
        init();
    }

    public AlertDialog(Context context, int themeResId) {
        super(context, themeResId);
        init();
    }

    protected AlertDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init();
    }

    private void init() {
        View contentView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_alert_layout, null);
        setContentView(contentView);
        tipTextView = (TextView) contentView.findViewById(R.id.txt_tip);
        btnSure =  (Button) contentView.findViewById(R.id.btn_sure);
        btnSure.setOnClickListener(this);
        setCanceledOnTouchOutside(false);
        setCancelable(false);
    }

    /**
     * 显示加载提示
     * @param text 提示文本
     */
    public void show(String text) {
        if(!TextUtils.isEmpty(text)) {
            tipTextView.setText(text);
        } else {
            tipTextView.setText("");
        }
        super.show();
    }
}
